package cn.wolfcode.util;

import cn.wolfcode.domain.Employee;
import cn.wolfcode.domain.Notice;
import cn.wolfcode.domain.UnreadNotice;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

public class  UserContext {
    public static final String USER_IN_SESSION = "USER_IN_SESSION";
    public static final String EXPRESSION_IN_SESSION = "EXPRESSION_IN_SESSION";
    public static final String NOTICE_IN_SESSION = "NOTICE_IN_SESSION";

    /**
     * c从session中获取登录用户
     */

    public static Employee getCurrentUser() {
        return (Employee) getSession().getAttribute(USER_IN_SESSION);
    }

    public static List<String> getExpressions() {
        return (List<String>) getSession().getAttribute(EXPRESSION_IN_SESSION);
    }

    public static HttpSession getSession() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return requestAttributes.getRequest().getSession();
    }
    public static void setExpressions(List<String> list) {
        getSession().setAttribute(EXPRESSION_IN_SESSION,list);
    }
    public static void setCurrentUser(Employee employee) {
        getSession().setAttribute(USER_IN_SESSION,employee);

    }



    public static void setUnreadNotice(UnreadNotice unreadNotice) {
        getSession().setAttribute(NOTICE_IN_SESSION,unreadNotice);
    }

    public static List<Notice> getUnreadNotice() {
        return (List<Notice>) getSession().getAttribute(NOTICE_IN_SESSION);
    }
}
